package com.ruoyi.zsyh.controller.applet.machine;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.EmptyUtils;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.zsyh.domain.SysDtArea;
import com.ruoyi.zsyh.domain.ZsyhAgentAddress;
import com.ruoyi.zsyh.domain.ZsyhElectricInstall;
import com.ruoyi.zsyh.domain.ZsyhElectricOrder;
import com.ruoyi.zsyh.service.ISysDtAreaService;
import com.ruoyi.zsyh.service.IZsyhAgentAddressService;
import com.ruoyi.zsyh.service.IZsyhElectricInstallService;
import com.ruoyi.zsyh.service.IZsyhElectricOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * 用户整机Controller
 */
@Controller
@RequestMapping("/applet/zsyh/userMachine")
public class ZsyhUserMachineAppletController extends BaseController
{

    @Autowired
    private IZsyhElectricOrderService zsyhElectricOrderService;

    @Autowired
    private IZsyhElectricInstallService zsyhElectricInstallService;

    @Autowired
    private ISysDtAreaService sysDtAreaService;

    /**
     * 获取省市县
     * @param pid
     * @return
     */
    @RequestMapping("/getAreaByPidMachine")
    @ResponseBody
    public AjaxResult getAreaByPid(String pid){
        pid = EmptyUtils.isEmpty(pid)?"0":pid;
        SysDtArea area = new SysDtArea();
        area.setAreaParentId(pid);
        return AjaxResult.success("获取成功", sysDtAreaService.selectSysDtAreaListOrderByInitials(area));
    }

    /**
     * 获取省市县 按照字母排列
     * @param pid
     * @return
     */
    @RequestMapping("/getAreaListByPidMachine")
    @ResponseBody
    public AjaxResult getAreaListByPid(String pid){
        pid = EmptyUtils.isEmpty(pid)?"0":pid;
        SysDtArea area = new SysDtArea();
        area.setAreaParentId(pid);
        List<SysDtArea> areaList = sysDtAreaService.selectSysDtAreaListOrderByInitials(area);
        List<SysDtArea> listA = new ArrayList<>();List<SysDtArea> listB = new ArrayList<>();List<SysDtArea> listC = new ArrayList<>();
        List<SysDtArea> listD = new ArrayList<>();List<SysDtArea> listE = new ArrayList<>();List<SysDtArea> listF = new ArrayList<>();
        List<SysDtArea> listG = new ArrayList<>();List<SysDtArea> listH = new ArrayList<>();List<SysDtArea> listI = new ArrayList<>();
        List<SysDtArea> listJ = new ArrayList<>();List<SysDtArea> listK = new ArrayList<>();List<SysDtArea> listL = new ArrayList<>();
        List<SysDtArea> listM = new ArrayList<>();List<SysDtArea> listN = new ArrayList<>();List<SysDtArea> listO = new ArrayList<>();
        List<SysDtArea> listP = new ArrayList<>();List<SysDtArea> listQ = new ArrayList<>();List<SysDtArea> listR = new ArrayList<>();
        List<SysDtArea> listS = new ArrayList<>();List<SysDtArea> listT = new ArrayList<>();List<SysDtArea> listU = new ArrayList<>();
        List<SysDtArea> listV = new ArrayList<>();List<SysDtArea> listW = new ArrayList<>();List<SysDtArea> listX = new ArrayList<>();
        List<SysDtArea> listY = new ArrayList<>();List<SysDtArea> listZ = new ArrayList<>();
        for(SysDtArea a:areaList){
            String initials = a.getAreaInitials();
            switch (initials){
                case "A":listA.add(a);break;                case "B":listB.add(a);break;                case "C":listC.add(a);break;
                case "D":listD.add(a);break;                case "E":listE.add(a);break;                case "F":listF.add(a);break;
                case "G":listG.add(a);break;                case "H":listH.add(a);break;                case "I":listI.add(a);break;
                case "J":listJ.add(a);break;                case "K":listK.add(a);break;                case "L":listL.add(a);break;
                case "M":listM.add(a);break;                case "N":listN.add(a);break;                case "O":listO.add(a);break;
                case "P":listP.add(a);break;                case "Q":listQ.add(a);break;                case "R":listR.add(a);break;
                case "S":listS.add(a);break;                case "T":listT.add(a);break;                case "U":listU.add(a);break;
                case "V":listV.add(a);break;                case "W":listW.add(a);break;                case "X":listX.add(a);break;
                case "Y":listY.add(a);break;                case "Z":listZ.add(a);break;
            }
        }
        Map mapA = new HashMap();
        mapA.put("letter", "A"); mapA.put("data", listA);
        Map mapB = new HashMap();
        mapB.put("letter", "B"); mapB.put("data", listB);
        Map mapC = new HashMap();
        mapC.put("letter", "C"); mapC.put("data", listC);
        Map mapD = new HashMap();
        mapD.put("letter", "D"); mapD.put("data", listD);
        Map mapE = new HashMap();
        mapE.put("letter", "E"); mapE.put("data", listE);
        Map mapF = new HashMap();
        mapF.put("letter", "F"); mapF.put("data", listF);
        Map mapG = new HashMap();
        mapG.put("letter", "G"); mapG.put("data", listG);
        Map mapH = new HashMap();
        mapH.put("letter", "H"); mapH.put("data", listH);
        Map mapI = new HashMap();
        mapI.put("letter", "I"); mapI.put("data", listI);
        Map mapJ = new HashMap();
        mapJ.put("letter", "J"); mapJ.put("data", listJ);
        Map mapK = new HashMap();
        mapK.put("letter", "K"); mapK.put("data", listK);
        Map mapL = new HashMap();
        mapL.put("letter", "L"); mapL.put("data", listL);
        Map mapM = new HashMap();
        mapM.put("letter", "M"); mapM.put("data", listM);
        Map mapN = new HashMap();
        mapN.put("letter", "N"); mapN.put("data", listN);
        Map mapO = new HashMap();
        mapO.put("letter", "O"); mapO.put("data", listO);
        Map mapP = new HashMap();
        mapP.put("letter", "P"); mapP.put("data", listP);
        Map mapQ = new HashMap();
        mapQ.put("letter", "Q"); mapQ.put("data", listQ);
        Map mapR = new HashMap();
        mapR.put("letter", "R"); mapR.put("data", listR);
        Map mapS = new HashMap();
        mapS.put("letter", "S"); mapS.put("data", listS);
        Map mapT = new HashMap();
        mapT.put("letter", "T"); mapT.put("data", listT);
        Map mapU = new HashMap();
        mapU.put("letter", "U"); mapU.put("data", listU);
        Map mapV = new HashMap();
        mapV.put("letter", "V"); mapV.put("data", listV);
        Map mapW = new HashMap();
        mapW.put("letter", "W"); mapW.put("data", listW);
        Map mapX = new HashMap();
        mapX.put("letter", "X"); mapX.put("data", listX);
        Map mapY = new HashMap();
        mapY.put("letter", "Y"); mapY.put("data", listY);
        Map mapZ = new HashMap();
        mapZ.put("letter", "Z"); mapZ.put("data", listZ);
        List list = new ArrayList();
        list.add(mapA);        list.add(mapB);        list.add(mapC);        list.add(mapD);
        list.add(mapE);        list.add(mapF);        list.add(mapG);        list.add(mapH);
        list.add(mapI);        list.add(mapJ);        list.add(mapK);        list.add(mapL);
        list.add(mapM);        list.add(mapN);        list.add(mapO);        list.add(mapP);
        list.add(mapQ);        list.add(mapR);        list.add(mapS);        list.add(mapT);
        list.add(mapU);        list.add(mapV);        list.add(mapW);        list.add(mapX);
        list.add(mapY);        list.add(mapZ);

        return AjaxResult.success("获取成功", list);
    }


    /**
     * 发布整机服务需求
     */
    @RepeatSubmit
    @RequestMapping("/saveMachineServiceOrder")
    @ResponseBody
    @Transactional
    public AjaxResult saveMachineServiceOrder(@RequestBody ZsyhElectricOrder electricOrder){
        electricOrder.setId(IdWorker.getId());
        electricOrder.setCreateTime(new Date());
        electricOrder.setOrderState("0");
        zsyhElectricOrderService.insertZsyhElectricOrder(electricOrder);
        return AjaxResult.success("成功");
    }

    /**
     * 添加 空调安装记录
     */
    @RepeatSubmit
    @RequestMapping("/saveElectricInstall")
    @ResponseBody
    @Transactional
    public AjaxResult saveElectricInstall(@RequestBody ZsyhElectricInstall zsyhElectricInstall){
        zsyhElectricInstall.setId(IdWorker.getId());
        zsyhElectricInstall.setCreateTime(new Date());
        zsyhElectricInstallService.insertZsyhElectricInstall(zsyhElectricInstall);
        return AjaxResult.success("成功");
    }

}
